﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Data.GameData;
using Data.GameData.Utils;

namespace GUIDialogs
{
    public partial class GameDetails : BaseDialog
    {
        public GameDetails()
        {
            InitializeComponent();
            InitialiseDialog();
        }

        private void InitialiseDialog()
        {
            errorProvider.SetIconPadding(gameNameTextBox, -20);

            if (Game.ActiveGame == null)
            {
                this.Text = "New Game";
                this.gameNameTextBox.Text = "";
                this.numRacesLabel.Text = "0";
                this.numSystemsLabel.Text = "0";
            }
            else
            {
                //this.gameNameTextBox.Enabled = false;
                this.gameNameTextBox.Text = Game.ActiveGame.Name;
                this.numRacesLabel.Text = Race.Races.Count().ToString();
                this.numSystemsLabel.Text = GameDataStore.GetStoreContents("StarSystems").Count().ToString();
            }
        }

        public string GameName
        {
            get { return gameNameTextBox.Text; }
            set { gameNameTextBox.Text = value; }
        }

        protected override bool IsValid()
        {
            errorProvider.SetError(gameNameTextBox, "");

            bool result = true;
            if (gameNameTextBox.Text.Length == 0)
            {
                errorProvider.SetError(gameNameTextBox, "You must enter a name.");
                result = false;
            }

            return result;
        }

        protected override void UpdateData()
        {
            if (Game.ActiveGame != null)
                Game.ActiveGame.Name = gameNameTextBox.Text;
        }
    }
}
